#version 420


layout(location = 0) in vec3 vertexPosition_modelspace; // position of vertex
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;	// normal vector


// Output data ; will be interpolated for each fragment.
out vec2 UV;	// texture coord
out vec3 Position_worldspace; // position of vertex in world space
out vec3 Normal_cameraspace;	// normal vector in camera space
out vec3 EyeDirection_cameraspace; // camera position in camera space (acoording to MV matrix)
out vec3 LightDirection_cameraspace; // light position in camea space

out float high;

uniform mat4 MVP; // space matrix
uniform mat4 M; // model matrix
uniform mat4 V; // view matrix
uniform vec3 LightPosition_worldspace; // position of light

void main() 
{            
   	// count vertex position acoording to model view matrix
	// set vertex to gl_Position
	vec4 v = vec4(vertexPosition_modelspace,1);

	gl_Position = MVP * v;
	//----------------------------------------------------- 
    
	// Position of the vertex, in worldspace : M * position
	Position_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;

	// Vector that goes from the vertex to the camera, in camera space.
	// In camera space, the camera is at the origin (0,0,0).
	vec3 vertexPosition_cameraspace = ( V * M * vec4(vertexPosition_modelspace,1)).xyz;
	EyeDirection_cameraspace = vec3(0,0,0) - vertexPosition_cameraspace;

	// Vector that goes from the vertex to the light, in camera space. M is ommited because it's identity.
	vec3 LightPosition_cameraspace = ( V * vec4(LightPosition_worldspace,1)).xyz;
	LightDirection_cameraspace = LightPosition_cameraspace + EyeDirection_cameraspace;

	// Normal of the the vertex, in camera space
	Normal_cameraspace = ( V * M * vec4(vertexNormal_modelspace,0)).xyz; 

	// high of vertex
	// used for texturing
    high = v.y;

	UV = vertexUV; // send UV coord to fragment shader 
}
